<!--
 * @Author: Freude Xu
 * @Date: 2021-10-06 15:40:44
 * @LastEditors: Freude Xu
 * @LastEditTime: 2021-10-06 15:46:31
 * @Description: 京东搜索框的案例
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>京东搜索框</title>
</head>

<body>
    <!-- 按下s键即可使得搜索框获得焦点 -->
    <input type="text">
    <script>
        var search = document.querySelector('input');
        //使用keyup比较合理，按键谈起时触发
        document.addEventListener('keyup', function(e) {
            // console.log(e.keyCode);
            if (e.keyCode === 83) {
                search.focus();
            }
        })
    </script>
</body>

</html>